<template>
<el-row type="flex" justify="center" class="tac" style="margin-top:50px;margin-bottom: 300px">
        
        <el-col :span="18">
            <el-row >
        <el-button @click="addpaper(5)">新增试卷</el-button>
        <el-table
        :data="list"
        border
        style="width: 100%"
        >
        
        <el-table-column
        prop="name"
        label="试卷名称"
        min-width="10%">
        <template slot-scope="scope">
            <router-link :to="{name:'introduce-pid',params:{pid:scope.row.id}}" style="text-decoration: none;font-size:15px;">
                <span style="color:#606266;font-size:14px">{{scope.row.name}}</span>
                </router-link>
        </template>
        
        </el-table-column>

        <el-table-column
        prop="categoryName"
        label="所属分类"
        min-width="10%">
        </el-table-column>
        
        <el-table-column
        prop="creatTime"
        label="创建时间"
        min-width="12%"
        >
            <template slot-scope="scope">
            <span style="margin-left: 3px">{{ scope.row.creatTime }}</span>
            </template>
        </el-table-column>

        <el-table-column
        prop="reviseTime"
        label="修改时间"
        min-width="12%"
        >
            <template slot-scope="scope">
            <span style="margin-left: 3px">{{ scope.row.reviseTime }}</span>
            </template>
        </el-table-column>

        <el-table-column
        prop="handle"
        label="操作"
        min-width="12%"
        align="center"
        >
            <template slot-scope="scope">
                <el-button
                size="mini"
                type="info"
                >
               <router-link :to="{name:'editExam-pid',params:{pid:scope.row.id}}" style="text-decoration: none;font-size:15px;">
                <span style="color:#fff;font-size:14px">修改</span>
                </router-link>
                </el-button>

    
                <el-button
                size="mini"
                type="danger"
                style="margin-left: 5%;font-size:14px"
                @click="handleDelete(scope.$index, scope.row)" >删除</el-button>
            </template>
        </el-table-column>
    </el-table>
            </el-row>
           <el-pagination
                background
                @size-change="fetchData"
                @current-change="fetchData"
                :current-page.sync="currentPage"
                :page-size.sync="pageSize"
                layout="prev, pager, next"
                :total="total"
                style="margin-top:2%;float: left"
                >
            </el-pagination>
        </el-col>
    </el-row>
</template>

<script>
import paperApi from '@/api/paperApi';
export default {
    asyncData(){
        return paperApi.getuserPaperList(1,8,5).then(response =>{
            // console.log(response.data.items[0].name)
            return {
                list:response.data.items,
                total:response.data.total
                }
        });
        activeIndex: '4';
    },

    data() {
      return {
        total:null,//总数量
        currentPage:  1,//当前页
        pageSize: 8,//每页大小
        editVisible:false,
      };
    },

    methods:{
         fetchData(){
            paperApi.getuserPaperList(this.currentPage,this.pageSize,this.user.id).then(response =>{
            if(response.items)
            this.list = response.data.items
            this.total = response.data.total
        })
    },

    // handleEdit(id){
    //     this.$router.push({name:'editExam-pid',params:{pid:id}})
    // },

    addpaper(id){
        this.$router.push({name:'addExam-id',params:{id:id}})
    }
    }
    
}
</script>

